import 'package:flutter/material.dart';
import 'package:get/get.dart';

/// 应用枚举管理
/// 集中管理所有应用中使用的枚举及其扩展方法

// 状态类型枚举
enum StatusType {
  success,  // 成功、在线
  warning,  // 警告
  error,    // 错误、离线
  info,     // 信息
  disabled, // 禁用、未激活
}

// 按钮类型枚举
enum ButtonType {
  primary,  // 主要
  success,  // 成功
  warning,  // 警告
  error,    // 错误
  disabled, // 禁用
}

// 设备状态枚举
enum DeviceStatus {
  inactive(0),  // 未激活
  online(1),    // 在线
  offline(2),   // 离线
  disabled(3);  // 禁用

  final int value;
  const DeviceStatus(this.value);

  static DeviceStatus fromValue(int value) {
    return DeviceStatus.values.firstWhere(
      (status) => status.value == value,
      orElse: () => DeviceStatus.offline,
    );
  }
}

// 告警级别枚举
enum AlertLevel {
  info(0),      // 信息
  warning(1),   // 警告
  error(2),     // 错误
  critical(3);  // 严重

  final int value;
  const AlertLevel(this.value);

  static AlertLevel fromValue(int value) {
    return AlertLevel.values.firstWhere(
      (level) => level.value == value,
      orElse: () => AlertLevel.info,
    );
  }
}

// 告警状态枚举
enum AlertStatus {
  generated(0),  // 产生
  recovered(1),  // 恢复
  confirmed(2);  // 已确认

  final int value;
  const AlertStatus(this.value);

  static AlertStatus fromValue(int value) {
    return AlertStatus.values.firstWhere(
      (status) => status.value == value,
      orElse: () => AlertStatus.generated,
    );
  }
}

// 产品类型枚举
enum ProductType {
  gateway(1),    // 网关
  device(2),     // 设备
  platform(3);   // 平台

  final int value;
  const ProductType(this.value);

  static ProductType fromValue(int value) {
    return ProductType.values.firstWhere(
      (type) => type.value == value,
      orElse: () => ProductType.device,
    );
  }
}

/// 枚举扩展 - StatusType
extension StatusTypeExtension on StatusType {
  // 获取状态显示名称
  String get displayName {
    switch (this) {
      case StatusType.success:
        return 'statusSuccess'.tr;
      case StatusType.warning:
        return 'statusWarning'.tr;
      case StatusType.error:
        return 'statusError'.tr;
      case StatusType.info:
        return 'statusInfo'.tr;
      case StatusType.disabled:
        return 'statusDisabled'.tr;
    }
  }
  
  // 获取状态图标
  IconData get icon {
    switch (this) {
      case StatusType.success:
        return Icons.check_circle;
      case StatusType.warning:
        return Icons.warning;
      case StatusType.error:
        return Icons.error;
      case StatusType.info:
        return Icons.info;
      case StatusType.disabled:
        return Icons.block;
    }
  }
}

/// 枚举扩展 - DeviceStatus
extension DeviceStatusExtension on DeviceStatus {
  // 获取设备状态显示名称
  String get displayName {
    switch (this) {
      case DeviceStatus.online:
        return 'deviceOnline'.tr;
      case DeviceStatus.offline:
        return 'deviceOffline'.tr;
      case DeviceStatus.inactive:
        return 'deviceInactive'.tr;
      case DeviceStatus.disabled:
        return 'deviceDisabled'.tr;
    }
  }
  
  // 获取设备状态对应的StatusType
  StatusType get statusType {
    switch (this) {
      case DeviceStatus.online:
        return StatusType.success;
      case DeviceStatus.offline:
        return StatusType.error;
      case DeviceStatus.inactive:
        return StatusType.warning;
      case DeviceStatus.disabled:
        return StatusType.disabled;
    }
  }
  
  // 获取设备状态图标
  IconData get icon {
    switch (this) {
      case DeviceStatus.online:
        return Icons.cloud_done;
      case DeviceStatus.offline:
        return Icons.cloud_off;
      case DeviceStatus.inactive:
        return Icons.pending_actions;
      case DeviceStatus.disabled:
        return Icons.block;
    }
  }
}

/// 枚举扩展 - AlertLevel
extension AlertLevelExtension on AlertLevel {
  // 获取告警级别显示名称
  String get displayName {
    switch (this) {
      case AlertLevel.info:
        return 'alertLevelInfo'.tr;
      case AlertLevel.warning:
        return 'alertLevelWarning'.tr;
      case AlertLevel.error:
        return 'alertLevelError'.tr;
      case AlertLevel.critical:
        return 'alertLevelCritical'.tr;
    }
  }
  
  // 获取告警级别对应的StatusType
  StatusType get statusType {
    switch (this) {
      case AlertLevel.info:
        return StatusType.info;
      case AlertLevel.warning:
        return StatusType.warning;
      case AlertLevel.error:
        return StatusType.error;
      case AlertLevel.critical:
        return StatusType.error;
    }
  }
  
  // 获取告警级别颜色
  Color get color {
    switch (this) {
      case AlertLevel.info:
        return Colors.blue;
      case AlertLevel.warning:
        return Colors.orange;
      case AlertLevel.error:
        return Colors.red;
      case AlertLevel.critical:
        return Colors.purple;
    }
  }
}

/// 枚举扩展 - AlertStatus
extension AlertStatusExtension on AlertStatus {
  // 获取告警状态显示名称
  String get displayName {
    switch (this) {
      case AlertStatus.generated:
        return 'alertStatusGenerated'.tr;
      case AlertStatus.recovered:
        return 'alertStatusRecovered'.tr;
      case AlertStatus.confirmed:
        return 'alertStatusConfirmed'.tr;
    }
  }
  
  // 获取告警状态图标
  IconData get icon {
    switch (this) {
      case AlertStatus.generated:
        return Icons.warning_amber_rounded;
      case AlertStatus.recovered:
        return Icons.check_circle_outline;
      case AlertStatus.confirmed:
        return Icons.done_all;
    }
  }
  
  // 获取告警状态对应的StatusType
  StatusType get statusType {
    switch (this) {
      case AlertStatus.generated:
        return StatusType.error;
      case AlertStatus.recovered:
        return StatusType.success;
      case AlertStatus.confirmed:
        return StatusType.disabled;
    }
  }
}

/// 枚举扩展 - ProductType
extension ProductTypeExtension on ProductType {
  // 获取产品类型显示名称
  String get displayName {
    switch (this) {
      case ProductType.gateway:
        return 'productTypeGateway'.tr;
      case ProductType.device:
        return 'productTypeDevice'.tr;
      case ProductType.platform:
        return 'productTypePlatform'.tr;
    }
  }
  
  // 获取产品类型图标
  IconData get icon {
    switch (this) {
      case ProductType.gateway:
        return Icons.router;
      case ProductType.device:
        return Icons.devices;
      case ProductType.platform:
        return Icons.cloud;
    }
  }
} 